<template>
  <basic-container :btnFlag="true">
    <div class="card-border">
      <card-header :header-data="headerData"></card-header>
      <div v-if="type == '起草文稿'">
        <h3 class="title">规划文本模板参考 ：</h3>
        <div class="top-btn">
          <el-button type="primary"
                     @click="preview(0)"
                     plain>发展规划
          </el-button>
          <el-button type="primary"
                     @click="preview(1)"
                     plain>空间规划
          </el-button>
          <el-button type="primary"
                     @click="preview(2)"
                     plain>专项规划
          </el-button>
          <el-button type="primary"
                     @click="preview(3)"
                     plain>区域规划
          </el-button>
        </div>
        <el-divider></el-divider>
      </div>
      <div class="card-body">
        <avue-crud :data="subjectListData"
                   :option="tableoption"
                   :page="page"
                   :table-loading="tableLoading"
                   @size-change="sizeChange"
                   @current-change="currentChange"
                   @search-change="searchChange"
                   @search-reset="searchReset"
                   class="avuecrud">
          <template slot-scope="scope"
                    slot="menu">
            <div class="menu-title"
                 @click.stop="materialCollection(scope.row,scope.index)"
                 v-if="type == '起草文稿'">
              <i class="iconfont iconview icon-primary"></i>
              <p class="menu-title-text">材料收集</p>
            </div>
            <div class="menu-title"
                 v-if="type == '征求意见'"
                 @click.stop="opinionCollectionList(scope.row,scope.index)">
              <i class="iconfont iconalter icon-warning"></i>
              <p class="menu-title-text">征求意见</p>
            </div>
            <div class="menu-title"
                 v-if="type == '征求意见'"
                 @click.stop="plaitReportHistory(scope.row,scope.index)">
              <i class="iconfont iconview icon-primary"></i>
              <p class="menu-title-text">查看意见</p>
            </div>
          </template>
        </avue-crud>
      </div>
      <detail-dialog :achievementId="achievementIdDD"
                     :pmuc="pmucDD"
                     :showDetailDialog.sync="showDetailDialog"
                     :key="achievementIdDD"></detail-dialog>
    </div>
  </basic-container>
</template>

<script>
  import {makeList} from "@/api/make";
  import {PROJECT_DIC} from "@/const/dict";
  import {getOpinionList} from "@/api/opinion";

  export default {
    name: "planningPlait",

    data() {
      return {
        dialogVisible: false,
        previewVisible: false,
        previewImgurl: "",
        headerData: {
          title: "起草文稿"
        },
        type: "",
        subjectListData: [],
        page: {
          total: 0, // 总页数
          currentPage: 1, // 当前页数
          pageSize: 10 // 每页显示多少条
        },
        qcwgtableoption: {
          page: true,
          menuWidth: 150,
          addBtn: false,
          editBtn: false,
          addRowBtn: false,
          indexLabel: "序号",
          index: true,
          cellBtn: false,
          delBtn: false,
  indexWidth:70,
          columnBtn: false,
          refreshBtn: false,
          filterBtn: false,
          searchBtn: false,
          keyId: "id",
          column: [
            {
              label: "规划名称",
              width: 300,
              prop: "title",
              cell: true,
              search: true,
              formatter: function (row, value, label, column) {
                return '<a style="cursor: pointer;" onclick="detailDialog(\'' + row.achievementId + '\'' + ',' + '\'' + row.pmuc + '\')">' + value + '</a>';
              },
            },
            {
              label: "规划类型",
              width: 100,
              prop: "category",
              type: "select",
              dicData: PROJECT_DIC.CATEGORY,
              cell: true
            },
            {
              label: "申报单位",
              width: 140,
              prop: "orgName",
              cell: true
            },
            {
              label: "收集次数",
              prop: "fileUploadTimes",
              cell: true
            },
            {
              label: "最后上传时间",
              prop: "fileLastUploadTime",
              cell: true,
              formatter: function (row, value, label, column) {
                if (value) {
                  return value.split(" ")[0];
                }
                return value;
              }
            }
          ]
        },
        zqyjtableoption: {
          page: true,
          menuWidth: 250,
          addBtn: false,
          editBtn: false,
          addRowBtn: false,
          indexLabel: "序号",
          index: true,
          cellBtn: false,
          delBtn: false,
          columnBtn: false,
  indexWidth:70,
          refreshBtn: false,
          filterBtn: false,
          searchBtn: false,
          keyId: "id",
          column: [
            {
              label: "规划名称",
              width: 350,
              prop: "title",
              cell: true,
              search: true,
              formatter: function (row, value, label, column) {
                return '<a style="cursor: pointer;" onclick="detailDialog(\'' + row.achievementId + '\'' + ',' + '\'' + row.pmuc + '\')">' + value + '</a>';
              },
            },
            {
              label: "规划类型",
              width: 100,
              prop: "category",
              type: "select",
              dicData: PROJECT_DIC.CATEGORY,
              cell: true
            },
            {
              label: "最后上传时间",
              prop: "makeLastUploadTime",
              cell: true,
              formatter: function (row, value, label, column) {
                if (value) {
                  return value.split(" ")[0];
                }
                return value;
              }
            },
            {
              label: "状态",
              prop: "makeState",
              cell: true,
              type: "select",
              dicData: PROJECT_DIC.MAKESTATE
            }
          ]
        },
        tableLoading: false,
        tableoption: {},
        achievementIdDD: null,
        pmucDD: null,
        showDetailDialog: null,
        titleLikes: '',
        categorys:''
      };
    },
    created() {
      this.getResultList(this.page);
      this.headerData.title = this.$route.query.type;
      this.type = this.$route.query.type;
      switch (this.type) {
        case "起草文稿":
          this.tableoption = this.qcwgtableoption;
          break;
        case "征求意见": {
          this.tableoption = this.zqyjtableoption;
          break;
        }
      }
      window.getOpinionDetail = this.getOpinionDetail;
      window.detailDialog = this.detailDialog;
    },
    methods: {
      preview(index) {
        this.$router.push({path: '/templatePlan', query: {id: index}})
      },
      detailDialog(achievementId, pmuc) {
        this.achievementIdDD = Number(achievementId);
        this.pmucDD = pmuc;
        this.showDetailDialog = true;
      },
      getResultList(page,params) {
        this.tableLoading = true;
        makeList(
          Object.assign({
            current: page.currentPage,
            size: page.pageSize,
            states: "0,1,2"
          },params)).then(response => {
          this.subjectListData = response.data.data.records;
          this.page.total = response.data.data.total;
          this.tableLoading = false;
        });
      },
      //重置回调
      searchReset() {
        this.getResultList(this.page);
      },
      //搜索回调
      searchChange(params) {
        this.page.currentPage = 1
        this.getResultList(this.page, this.dealSearchParam(params));
      },
      // 处理搜索过滤
      dealSearchParam(params) {
        if (params.title) {
          params.titleLike = params.title
        }else{
          params.titleLike =""
        }
        this.titleLikes=  params.titleLike;
        return params;
      },
      currentChange(currentPage) {
        let page = this.page;
        page.currentPage = currentPage;
        let params={titleLike: this.titleLikes}
        this.getResultList(page, params);
      },
      sizeChange(pageSize) {
        let page = this.page;
        page.pageSize = pageSize;
        let params={titleLike: this.titleLikes}
        this.getResultList(page, params);
      },
      // 材料收集跳转页面
      materialCollection(row) {
        let src = `/materialCollection/detail/${row.achievementId}`;
        this.$router.push({
          path: src,
          query: {
            subjectTitle: row.title,
            type: "1"
          }
        });
      },
      // 版本管理
      plaitReportHistory(row, index) {
        getOpinionList(
          Object.assign({
            current: 0,
            size: 10,
            relateId: row.achievementId,
            type: "3"
          })
        ).then(response => {
          let records = response.data.data.records;
          if (records && records.length > 0) {
            let row = records[0];
            let src = `/collectionListMakeTxt/list/${row.relateId}`;
            this.$router.push({
              path: src,
              query: {
                type: "3",
                title: row.achievementTitle
              }
            });
          } else {
            this.$notify({
              title: "提醒",
              type: "warning",
              message: "暂无征求意见！",
              duration: 2000
            });
          }
        });
      },
      // 查看详情
      getOpinionDetail(id) {
        let src = `/opinionDetail/detail/${id}`;
        this.$router.push({
          path: src
        });
      },
      // 上传文稿
      uploadTxt(row, index) {
        let src = `/addMake/add/${row.achievementId}`;
        this.$router.push({
          path: src
        });
      },
      // 征求意见
      opinionCollectionList(row, index) {
        let src = `/opinionCollection/add/${row.achievementId}`;
        this.$router.push({
          path: src,
          query: {
            type: "3",
            title: row.title,
            orgName: row.orgName,
          }
        });
      },
      // 意见反馈
      feedback(row, index) {
        let src = `/opinionFeedback/add/${row.opinionId}`;
        this.$router.push({
          path: src,
          query: {
            targetId: row.targetId,
            toDoOrnot: "0"
          }
        });
      }
    }
  };
</script>

<style lang="scss" scoped>
  .line {
    line-height: 40px;
    font-size: 20px;
    font-weight: 600;

    span {
      margin-right: 20px;
    }
  }

  .top-btn {
    display: flex;
    justify-content: space-around;
    height: 60px;
    align-items: center;
  }

  .el-carousel__item h3 {
    color: #475669;
    font-size: 18px;
    opacity: 0.75;
    line-height: 300px;
    margin: 0;
  }

  .el-carousel__item:nth-child(2n) {
    background-color: #99a9bf;
  }

  .el-carousel__item:nth-child(2n + 1) {
    background-color: #d3dce6;
  }

  .title {
    font-size: 16px;
    padding-left: 10px;
    color: #020202;
  }

  .card-border {
    position: relative;
  }

  .down {
    position: absolute;
    right: 20px;
    top: 220px;
  }
</style>
